#ifndef _CRT_THREADPOOL_H_
#define _CRT_THREADPOOL_H_

#include <crt_core.hpp>
#include <crt_funcb.h>
#include <crt_sem.h>
#include <crt_thread.h>

#ifdef __cplusplus
extern "C" {
#endif

typedef struct io_thread_s io_thread_t;

struct io_thread_s {
    void* ctx;
    void* parent_context;
    io_func_t func;
    _thread_t threadhandler;
    int id;
};

typedef struct _threadpool_s _threadpool_t;

struct _threadpool_s {
    void* ctx;
    unsigned long count;
    io_func_t func;
    io_thread_t* threads;
    _sem_t sem;
    _sem_t exit;
};

int init_threadpool(_threadpool_t* pool);
int start_threadpool(_threadpool_t* pool);
int stop_threadpool(_threadpool_t* pool);
int uinit_threadpool(_threadpool_t* pool);

#ifdef __cplusplus
}
#endif

#endif
